package com.wdl.web.controller;

import com.wdl.web.exception.UserException;
import com.wdl.web.model.User;
import com.wdl.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created by wdl on 2016/11/10.
 */
@Controller
public class UserController {
    @Autowired
    private UserService service;

    @RequestMapping("/users")
    public String showAllUsers(Model model) {
        List<User> users = service.getUsers();
        model.addAttribute("users", users);
        System.out.println("users.length:" + users.size());
        return "Users";
    }

    @RequestMapping("/errors")
    public String showError(int id) {
        if (id == 1)
            throw new UserException();
        return "index";
    }
}
